package com.yaodian100.ec.activity;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.yaodian100.ec.activity.entity.ActivityPageBlock;
import com.yaodian100.ec.activity.entity.ActivityPageBlockBanner;
import com.yaodian100.ec.activity.entity.ActivityPageBlockTemplate;
import com.yaodian100.ec.activity.service.ActivityPageBlockService;
import com.yaodian100.ec.activity.service.ActivityPageBlockTemplateService;
import com.yaodian100.ec.common.web.AbstractAction;

public class ActivityPageBlockBannerAction extends AbstractAction {
	private static final long serialVersionUID = -2379109652635941375L;

	@Autowired
	private ActivityPageBlockService activityPageBlockService;
	@Autowired
	private ActivityPageBlockTemplateService activityPageBlockTemplateService;
	
	private Long pageId;
	private ActivityPageBlock block;
	private ActivityPageBlockTemplate template;
	private List<ActivityPageBlockBanner> blockBanners;
	
	public String editBlockBanner() {
		this.block = this.activityPageBlockService.get(this.block.getId());
		//this.template = this.activityPageBlockTemplateService.get(this.block.getBlockTemplateId());
		this.template = this.block.getTemplate();
		this.blockBanners = this.block.getBanners();
		//初始化
		for (int i=this.blockBanners.size();i<this.template.getBigImageCount().intValue();i++) {
			ActivityPageBlockBanner banner = new ActivityPageBlockBanner();
			this.blockBanners.add(banner);
		}
		return "editBlockBanner";
	}
	
	public String saveBlockBanners() {
		block.setBanners(this.blockBanners);
		this.block = this.activityPageBlockService.saveBlockBanners(block);
		this.pageId = this.block.getPageId();
		return "editPage";
	}

	public ActivityPageBlockService getActivityPageBlockService() {
		return activityPageBlockService;
	}

	public void setActivityPageBlockService(
			ActivityPageBlockService activityPageBlockService) {
		this.activityPageBlockService = activityPageBlockService;
	}

	public ActivityPageBlockTemplateService getActivityPageBlockTemplateService() {
		return activityPageBlockTemplateService;
	}

	public void setActivityPageBlockTemplateService(
			ActivityPageBlockTemplateService activityPageBlockTemplateService) {
		this.activityPageBlockTemplateService = activityPageBlockTemplateService;
	}

	public Long getPageId() {
		return pageId;
	}

	public void setPageId(Long pageId) {
		this.pageId = pageId;
	}

	public ActivityPageBlock getBlock() {
		return block;
	}

	public void setBlock(ActivityPageBlock block) {
		this.block = block;
	}

	public ActivityPageBlockTemplate getTemplate() {
		return template;
	}

	public void setTemplate(ActivityPageBlockTemplate template) {
		this.template = template;
	}

	public List<ActivityPageBlockBanner> getBlockBanners() {
		return blockBanners;
	}

	public void setBlockBanners(List<ActivityPageBlockBanner> blockBanners) {
		this.blockBanners = blockBanners;
	}
	
	
}
